import { postHandle } from '@/api'
export const mixin = {
  data() {
    return {
      hotWorkTypeData: [],
      possibleHazardsData: [],
      implementationData: [],
      safetyMeasuresData: [],
      memberData: [],
      approvalData: [],
      temporaryWorkersData: [],
      maxPageSize: {
        p: 1,
        ps: 9999
      }
    }
  },
  computed: {
    entSpaceId() {
      return this.$store.getters.entSpaceId
    },
    spaceId() {
      return this.$store.getters.entSpaceId
    }
  },
  methods: {
    // 动火作业类型
    getHotWorkTypeData() {
      let params = {
        d: {
          filters: [
            {
              field: 'pdCode',
              operator: 'EQUALS',
              value: 'hotWorkType'
            }
          ],
          page: this.maxPageSize,
          sorts: [{ field: 'ct', isDesc: false }]
        }
      }
      postHandle('/api/v1/welder-sbtx-second/dictionary', params).then(res => {
        this.hotWorkTypeData = res.result
      })
    },
    // 可能产生的危害
    getPossibleHazardsData() {
      let params = {
        d: {
          filters: [
            {
              field: 'pdCode',
              operator: 'EQUALS',
              value: 'possibleHazards'
            }
          ],
          page: this.maxPageSize,
          sorts: [{ field: 'ct', isDesc: false }]
        }
      }
      postHandle('/api/v1/welder-sbtx-second/dictionary', params).then(res => {
        this.possibleHazardsData = res.result
      })
    },
    // 相关许可落实情况
    getImplementationData() {
      let params = {
        d: {
          filters: [
            {
              field: 'pdCode',
              operator: 'EQUALS',
              value: 'implementation'
            }
          ],
          page: this.maxPageSize,
          sorts: [{ field: 'ct', isDesc: false }]
        }
      }
      postHandle('/api/v1/welder-sbtx-second/dictionary', params).then(res => {
        this.implementationData = res.result
      })
    },
    // 安全措施
    getSafetyMeasuresData() {
      let params = {
        d: {
          filters: [
            {
              field: 'pdCode',
              operator: 'EQUALS',
              value: 'safetyMeasures'
            }
          ],
          page: this.maxPageSize,
          sorts: [{ field: 'ct', isDesc: false }]
        }
      }
      postHandle('/api/v1/welder-sbtx-second/dictionary', params).then(res => {
        this.safetyMeasuresData = res.result
      })
    },
    // 企业普通员工
    getMembersData() {
      let params = {
        d: {
          page: this.maxPageSize
        }
      }
      postHandle('/api/v1/welder-uac-second/space-user-member-comb/get-list', params).then(res => {
        this.memberData = res.result
      })
    },
    // 根据企业entSpaceId获取企业全部的管理员
    getApprovalData() {
      postHandle(`/api/v1/welder-uac-second/space-user-member-role-comb/get-ent-admin/${this.entSpaceId}`, {
        d: { page: this.maxPageSize }
      }).then(res => {
        this.approvalData = res.result
      })
    },
    // 项目临时工
    getTemporaryWorkersData() {
      let params = {
        d: {
          c: [
            {
              key: 'spaceId',
              value: this.spaceId
            }
          ],
          filters: [
            {
              field: 'workCode',
              operator: 'EQUALS',
              value: 'LSG'
            },
            {
              field: 'spaceId',
              operator: 'EQUALS',
              value: this.spaceId
            }
          ],
          page: this.maxPageSize
        }
      }
      postHandle(`/api/v1/welder-uac-second/space-organization-member-comb/get-member-list`, params).then(res => {
        this.temporaryWorkersData = res.result
      })
    }

  },
  created() {
    this.getHotWorkTypeData()
    this.getPossibleHazardsData()
    this.getImplementationData()
    this.getSafetyMeasuresData()
    this.getMembersData()
    this.getApprovalData()
    this.getTemporaryWorkersData()
  }
}
